<?php

class BaseAdminController extends Controller
{

  protected $permissions;

  protected function initialize()
  {
    s::setExceptionHandler('LoginRequiredException', array($this, 'loginRequiredHandler'));
  }

  public function loginRequiredHandler()
  {
    $redirect = $this->request()->base() . $this->request()->uri();
    $this->response()->redirect(array('/admin/account', array('action' => 'login', 'redirect' => $redirect)));
  }

  protected function beforeAction($action)
  {
    Account::validate('admin');
    Account::validate($this->permissions);

    parent::beforeAction($action);
  }

}
